package com.usabb.service.impl;

import com.usabb.pojo.vo.MaternityBaseVO;
import com.usabb.service.LabelRelationService;
import com.usabb.service.PromiseRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.usabb.dao.MaternityBaseDao;
import com.usabb.domain.MaternityBaseDO;
import com.usabb.service.MaternityBaseService;
import com.ifast.common.base.CoreServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * <pre>
 * 月子中心基础表
 * </pre>
 * <small> 2019-08-19 18:03:27 | Aron</small>
 */
@Service
public class MaternityBaseServiceImpl extends CoreServiceImpl<MaternityBaseDao, MaternityBaseDO> implements MaternityBaseService {

    @Autowired
    private LabelRelationService labelRelationService;
    @Autowired
    private PromiseRelationService promiseRelationService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertVo(MaternityBaseVO baseVO) {
        log.info("MaternityBase insert - input: {}", baseVO);
        //verify
        final MaternityBaseDO baseDO = baseVO.toDo();
        final boolean insert = this.insert(baseDO);

        final Long[] labelIds = baseVO.getLabelIds();
        final Long[] promiseIds = baseVO.getPromiseIds();

        labelRelationService.addAll(baseDO.getId(), labelIds);
        promiseRelationService.addAll(baseDO.getId(), promiseIds);

        log.info("MaternityBase insert - Done.");
    }



}
